Unlike front-end scripts which run on the client / browser-side, back-end scripts run directly on the Node.js environment of the Trilium server.
Back-end scripts can be used both on a Server Installation (where it will run on the device the server is running on), or on the Desktop Installation (where it will run on the PC).
The benefit of backend scripts is that they can be pretty powerful, for example to have access to the underlying system, for example it can read files or execute processes.
However, the main benefit of backend scripts is that they have easier access to the notes since the information about them is already loaded in memory. Whereas on the client, notes have to be manually loaded first.
Create a new Code note and select the language JavaScript (Trilium backend).
Backend scripts can be either run manually (via the Execute button on the script page), or they can be triggered on certain events.
When a script run manually or from a launcher throws an error, Trilium shows a Scripting error notification with the error message and a link to the note that failed. If the error comes from a child note the script requires, the link points to that child note. Changes the script made to notes before the error are rolled back.
In addition, scripts can be run automatically when the server starts up, on a fixed time interval or when a certain event occurs (such as an attribute being modified). For more information, see the dedicated Events page.
Trilium exposes a set of APIs that can be directly consumed by scripts,
under the api object. For a reference of this API, see Backend API.